Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Grid

Imports ComponentGo.Calendars

Imports Phoenix.DataAccess
Imports Phoenix.Helpers

Namespace Forms.Area

    Public Class ServiceArea : Inherits GridAreaBase

        Public Event ServiceSelectionChanged(ByVal sender As Object, ByVal args As EventArgs)

#Region " Windows Form Designer generated code "

        Public Sub New()
            MyBase.New()

            'This call is required by the Windows Form Designer.
            InitializeComponent()

            'Add any initialization after the InitializeComponent() call
            GridView = ServiceView
        End Sub

        'UserControl overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        Friend WithEvents GridControlServices As DevExpress.XtraGrid.GridControl
        Friend WithEvents ServiceView As DevExpress.XtraGrid.Views.Grid.GridView
        Friend WithEvents Label As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents Type As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents ServiceIconColumn As DevExpress.XtraGrid.Columns.GridColumn
        Friend WithEvents ServiceIconRI As DevExpress.XtraEditors.Repository.RepositoryItemImageComboBox
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.GridControlServices = New DevExpress.XtraGrid.GridControl
            Me.ServiceView = New DevExpress.XtraGrid.Views.Grid.GridView
            Me.Label = New DevExpress.XtraGrid.Columns.GridColumn
            Me.Type = New DevExpress.XtraGrid.Columns.GridColumn
            Me.ServiceIconColumn = New DevExpress.XtraGrid.Columns.GridColumn
            Me.ServiceIconRI = New DevExpress.XtraEditors.Repository.RepositoryItemImageComboBox
            CType(Me.GridControlServices, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.ServiceView, System.ComponentModel.ISupportInitialize).BeginInit()
            CType(Me.ServiceIconRI, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.SuspendLayout()
            '
            'GridControlServices
            '
            Me.GridControlServices.Dock = System.Windows.Forms.DockStyle.Fill
            '
            'GridControlServices.EmbeddedNavigator
            '
            Me.GridControlServices.EmbeddedNavigator.Name = ""
            Me.GridControlServices.Location = New System.Drawing.Point(0, 0)
            Me.GridControlServices.MainView = Me.ServiceView
            Me.GridControlServices.Name = "GridControlServices"
            Me.GridControlServices.RepositoryItems.AddRange(New DevExpress.XtraEditors.Repository.RepositoryItem() {Me.ServiceIconRI})
            Me.GridControlServices.Size = New System.Drawing.Size(376, 416)
            Me.GridControlServices.Styles.AddReplace("FocusedCell", New DevExpress.Utils.ViewStyleEx("FocusedCell", "Grid", New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(204, Byte)), CType((((((DevExpress.Utils.StyleOptions.StyleEnabled Or DevExpress.Utils.StyleOptions.UseBackColor) _
                                Or DevExpress.Utils.StyleOptions.UseDrawFocusRect) _
                                Or DevExpress.Utils.StyleOptions.UseFont) _
                                Or DevExpress.Utils.StyleOptions.UseForeColor) _
                                Or DevExpress.Utils.StyleOptions.UseImage), DevExpress.Utils.StyleOptions), System.Drawing.SystemColors.Highlight, System.Drawing.SystemColors.HighlightText, System.Drawing.SystemColors.InactiveCaption, System.Drawing.Drawing2D.LinearGradientMode.Horizontal))
            Me.GridControlServices.TabIndex = 2
            Me.GridControlServices.Text = "Services"
            '
            'ServiceView
            '
            Me.ServiceView.Columns.AddRange(New DevExpress.XtraGrid.Columns.GridColumn() {Me.Label, Me.Type, Me.ServiceIconColumn})
            Me.ServiceView.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.None
            Me.ServiceView.GridControl = Me.GridControlServices
            Me.ServiceView.GroupPanelText = ""
            Me.ServiceView.Name = "ServiceView"
            Me.ServiceView.OptionsBehavior.AllowIncrementalSearch = True
            Me.ServiceView.OptionsBehavior.ShowEditorOnMouseUp = True
            Me.ServiceView.OptionsDetail.EnableMasterViewMode = False
            Me.ServiceView.OptionsSelection.InvertSelection = True
            Me.ServiceView.OptionsSelection.MultiSelect = True
            Me.ServiceView.OptionsView.ShowIndicator = False
            Me.ServiceView.OptionsView.ShowVertLines = False
            '
            'Label
            '
            Me.Label.Caption = "Service"
            Me.Label.FieldName = "Label"
            Me.Label.Name = "Label"
            Me.Label.Options = CType((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.Label.VisibleIndex = 1
            Me.Label.Width = 172
            '
            'Type
            '
            Me.Type.Caption = "Type"
            Me.Type.FieldName = "Type"
            Me.Type.Name = "Type"
            Me.Type.Options = CType((((((((DevExpress.XtraGrid.Columns.ColumnOptions.CanFiltered Or DevExpress.XtraGrid.Columns.ColumnOptions.CanMoved) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanGrouped) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanResized) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanSorted) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.CanFocused) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.ShowInCustomizationForm) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.Type.VisibleIndex = 2
            Me.Type.Width = 178
            '
            'ServiceIconColumn
            '
            Me.ServiceIconColumn.ColumnEdit = Me.ServiceIconRI
            Me.ServiceIconColumn.Name = "ServiceIconColumn"
            Me.ServiceIconColumn.Options = CType(((DevExpress.XtraGrid.Columns.ColumnOptions.ReadOnly Or DevExpress.XtraGrid.Columns.ColumnOptions.FixedWidth) _
                        Or DevExpress.XtraGrid.Columns.ColumnOptions.NonEditable), DevExpress.XtraGrid.Columns.ColumnOptions)
            Me.ServiceIconColumn.VisibleIndex = 0
            Me.ServiceIconColumn.Width = 24
            '
            'ServiceIconRI
            '
            Me.ServiceIconRI.AutoHeight = False
            Me.ServiceIconRI.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)})
            Me.ServiceIconRI.Items.AddRange(New Object() {New DevExpress.XtraEditors.Controls.ImageComboBoxItem("", Nothing, 6)})
            Me.ServiceIconRI.Name = "ServiceIconRI"
            '
            'ServiceArea
            '
            Me.Controls.Add(Me.GridControlServices)
            Me.Name = "ServiceArea"
            Me.Size = New System.Drawing.Size(376, 416)
            CType(Me.GridControlServices, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.ServiceView, System.ComponentModel.ISupportInitialize).EndInit()
            CType(Me.ServiceIconRI, System.ComponentModel.ISupportInitialize).EndInit()
            Me.ResumeLayout(False)

        End Sub

#End Region

#Region " Event Handlers "
        Private Sub Form_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
            If DesignMode Then Return

            Me.GridControlServices.DataSource = New DataView(AppDataLayer.Services)
        End Sub

#End Region

#Region " Area Behaviour "

        Public Overrides ReadOnly Property Icon() As DevExpress.XtraEditors.Repository.RepositoryItemImageComboBox
            Get
                Return ServiceIconRI
            End Get
        End Property

        Public Overrides ReadOnly Property IconColumn() As DevExpress.XtraGrid.Columns.GridColumn
            Get
                Return ServiceIconColumn
            End Get
        End Property

#End Region

#Region " Cut/Copy/Delete Operations "
        Public Overrides Function CanCopy() As Boolean
            Return Security.CanCreateService
        End Function

        Public Overrides Function CanDelete() As Boolean
            Return Security.CanDeleteService
        End Function

        Public Overrides Sub Paste(ByVal arr As IList)
            If arr Is Nothing Then Return

            For Each obj As DataRow In arr
                Dim item As DataAccess.DataSetData.Service = Helpers.ServiceHelper.Copy(CType(obj, DataAccess.DataSetData.Service))
                Helpers.ServiceHelper.UpdateService(item, Me)
            Next
        End Sub

        Public Overrides Sub Delete(ByVal arr As IList)
            If arr Is Nothing Then Return

            Helpers.ServiceHelper.DeleteServices(arr, Me)
        End Sub

#End Region

        Private Sub ServiceView_SelectionChanged(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.SelectionChangedEventArgs) Handles ServiceView.SelectionChanged
            RaiseEvent ServiceSelectionChanged(Me, Nothing)
        End Sub

        Private mInDragDrop As Boolean = False

        Private Sub ServiceView_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ServiceView.MouseDown
            If e.Button = MouseButtons.Left Then
                mInDragDrop = False
            End If
        End Sub

        Private Sub ServiceView_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ServiceView.MouseMove
            If (e.Button = MouseButtons.Left) And (Not mInDragDrop) Then
                If ServiceView.State = GridState.Normal Then
                    Dim r As DataSetData.Service = CType(ServiceView.GetDataRow(ServiceView.FocusedRowHandle()), DataSetData.Service)
                    If Not r Is Nothing Then
                        mInDragDrop = True
                        DoDragDrop(r, DragDropEffects.All)
                    End If
                End If
            End If
        End Sub

        Private Sub ServiceView_FocusedRowChanged(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles ServiceView.FocusedRowChanged
            Dim rows() As Integer = ServiceView.GetSelectedRows
            If Not rows Is Nothing Then
                For Each row As Integer In rows
                    ServiceView.UnselectRow(row)
                Next
            End If

            ServiceView.SelectRow(e.FocusedRowHandle)

        End Sub

    End Class

End Namespace
